#include <cstdio>
#include <cstdlib>
#include "BTreeMap.h"

// 初始化 BTreeMap
BTreeMap* init_btree_map() {
    BTreeMap* map = (BTreeMap*)malloc(sizeof(BTreeMap));
    if (map) {
        map->root = NULL;
    }
    return map;
}

// 释放 BTreeNode 内存的递归函数
void free_btree_node(BTreeNode* node) {
    if (node) {
        free_btree_node(node->left);
        free_btree_node(node->right);
        free(node);
    }
}

// 释放 BTreeMap 内存
void free_btree_map(BTreeMap* map) {
    if (map) {
        free_btree_node(map->root);
        free(map);
    }
}

int b_tree_map_main_test() {
    // 使用示例：创建一个 BTreeMap，并插入一些数据
    BTreeMap* map = init_btree_map();
    if (map) {
        // 插入数据
        BTreeNode* node1 = (BTreeNode*)malloc(sizeof(BTreeNode));
        node1->key = 1;
        node1->value.float_value = 3.14;
        node1->left = node1->right = NULL;
        map->root = node1;

        BTreeNode* node2 = (BTreeNode*)malloc(sizeof(BTreeNode));
        node2->key = 2;
        node2->value.vector_value.x = 1.0;
        node2->value.vector_value.y = 2.0;
        node2->value.vector_value.z = 3.0;
        node2->left = node2->right = NULL;
        map->root->right = node2;

        // 最后释放 BTreeMap 内存
        free_btree_map(map);
    } else {
        printf("Failed to initialize BTreeMap.\n");
    }

    return 0;
}
